﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using TD.bom;

namespace TD.Application
{
    /// <summary>
    /// Cette classe représente l'élément racine de l'IHM de l'application
    /// </summary>
    public partial class MainPage : UserControl
    {
        /// <summary>
        /// Ecran d'accueil
        /// </summary>
        public HomeForm HomeForm
        {
            get;
            protected set;
        }

        /// <summary>
        /// Ecran de jeu
        /// </summary>
        public GameForm GameForm
        {
            get;
            protected set;
        }

        /// <summary>
        /// Ecran de sauvegarde d'une partie
        /// </summary>
        public SaveGameForm SaveGameForm
        {
            get;
            protected set;
        }

        /// <summary>
        /// Ecran de chargement d'une partie
        /// </summary>
        public LoadGameForm LoadGameForm
        {
            get;
            protected set;
        }

        /// <summary>
        /// Ecran de paramétrage du jeu
        /// </summary>
        public SettingsForm SettingsForm
        {
            get;
            protected set;
        }

        /// <summary>
        /// Ecran actif
        /// </summary>
        public FormBase ActiveForm
        {
            get { return Content as FormBase; /* renvoie null si le type n'est pas compatible*/ }
            set { Content = value; }
        }

        /// <summary>
        /// Instance en cours de la page 
        /// </summary>
        public static MainPage Instance
        {
            get
            {
                return (System.Windows.Application.Current.RootVisual as MainPage);
            }
        }

        /// <summary>
        /// Constructeur
        /// </summary>
        public MainPage()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(OnLoaded);
        }

        /// <summary>
        /// Initialisation des IHM de l'application
        /// </summary>
        void OnLoaded(object sender, RoutedEventArgs e)
        {
            // On instancie tous les écrans pour les utiliser ultérieurement
            HomeForm = new HomeForm();
            GameForm = new GameForm();
            LoadGameForm = new LoadGameForm();
            SaveGameForm = new SaveGameForm();
            SettingsForm = new SettingsForm();

            // ... mais seul l'écran d'accueil est visible 
            HomeForm.Activate();
        }

    }
}
